﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaMusaSoft.RPS.RPSServices
{
    static class Helper
    {

        /*Stopwatch example
         *  Stopwatch watch = new Stopwatch();
            watch.Start();
            Action to measure.
         * * watch.Stop();
            var ts = watch.Elapsed;
            string elapsedTime = string.Format("{00:00}.{1:00}.{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
            Console.WriteLine(elapsedTime, "RunTime");
         * 
         * */
        public static string DateMiror(string s)
        {
            if(string.IsNullOrEmpty(s)) return "";
            if (s.Length == 10)
            {

                return new StringBuilder().Append(s.Substring(s.Length - 2, 2))
                                           .Append("/")
                                           .Append(s.Substring(s.Length - 5, 2))
                                           .Append("/")
                                           .Append(s.Substring(0, 4))
                                           .ToString();
            }
            if (s.Length == 8)
            {
                return new StringBuilder().Append(s.Substring(s.Length - 2, 2))
                    .Append("/")
                    .Append(s.Substring(s.Length - 4, 2))
                    .Append("/")
                    .Append(s.Substring(0, 4))
                    .ToString();
            }
            return s;
        }
        public static DateTime ParseDateString(string dateString)
        {

            string formattedDateString = PutMask(dateString);
            DateTime date;
            if (DateTime.TryParse(formattedDateString, out date))
            {
                return date;
            }
            return DateTime.Now;
        }
        public static string PutMask(string dateString)
        {
            if (!string.IsNullOrEmpty(dateString))
            {
                string y = dateString.Substring(0, 4);
                string m = dateString.Substring(4, 2);
                string d = dateString.Substring(6, 2);
                string f = y + "/" + m + "/" + d;
                return f;
            }
            return "";

        }
    }
}
